
var app = getApp();
var ApiUrl = app.globalData.ApiUrl;
Page({
  data: {
    jump:'',
    winHeight: "",//窗口高度
    currentTab: 0, //预设当前项的值
    scrollLeft: 0, //tab标题的滚动条位置
    hide_red_bao:false,
    expertList: [
      { //假数据
        id:1,
        u_name:'putong',
        text:'普通红包',
        data_list:[
        ]
      },
      { //假数据
        id: 2,
        u_name: 'pingshouqi',
        text: '拼手气红包',
        data_list: [  ]
      },
      { //假数据
        id: 3,
        u_name: 'kouling',
        text: '口令等额红包',
        data_list: [
        ]
      },
      { //假数据
        id: 3,
        u_name: 'koulingzuiji',
        text: '口令随机红包',
        data_list: [
        ]
      }
    ],
    num:'',
    money:'', 
    pass:'', 
    cont:'',
    send_red_bag_list:''
  },
  bindKeyInput: function (e) {
    this.setData({
      inputValue: e.detail.value
    })
  },
  // go_order_detail(){
  //   wx.navigateTo({
  //     url: '/pages/order_detail/order_detail'
  //   })
  // },
  // go_shopping_cart(){//跳转购物车
  //   wx.switchTab({
  //     url: '/pages/shopping_cart/shopping_cart'
  //   })
  // },
  // 滚动切换标签样式
  switchTab: function (e) {
    this.setData({
      currentTab: e.detail.current
    });
    console.log('滚动切换标签样式==>',this.data.currentTab);
    this.checkCor();
  },
  // 点击标题切换当前页时改变样式
  swichNav: function (e) {
    var cur = e.target.dataset.current;
    if (this.data.currentTaB == cur) { return false; }
    else {
      this.setData({
        currentTab: cur
      })
    }
  },
  //判断当前滚动超过一屏时，设置tab标题滚动条。
  checkCor: function () {
    if (this.data.currentTab > 4) {
      this.setData({
        scrollLeft: 300
      })
    } else {
      this.setData({
        scrollLeft: 0
      })
    }
  },
  aaaa(){
    console.log('aaa')
    wx.reLaunch({
      url: '/pages/red_envelopes/Send_red_packets'
    })
  },
  onLoad: function (option) {
    console.log("options============" + option)
    var that = this
//console.log(u_name, 8888888);
    //跳转到我的订单对应的栏目中
//     for (let i = 0; i < that.data.expertList.length;i++){
//       if (that.data.expertList[i].u_name == u_name){
//         let cur = i;
// //console.log(cur,77777);
//         if (this.data.currentTaB == cur) { return false; }
//         else {
//           this.setData({
//             currentTab: cur
//           })
//         }
//       }
//     }
    //  高度自适应
    wx.getSystemInfo({
      success: function (res) {
        var clientHeight = res.windowHeight,
          clientWidth = res.windowWidth,
          rpxR = 750 / clientWidth;
        var calc = clientHeight * rpxR - 180;
//console.log(calc)
        that.setData({
          winHeight: calc
        });
      }
    });
  },
  footerTap: app.footerTap,
  //发红包
  //http://192.168.0.120/upload/mobile/index.php?act=red_bag&op=send_red_bag
  send_red_bag(){

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },
  //普通红包信息
  bindmoney1(e){
    let money = e.detail.value;
    console.log('普通红包钱：==》', money);
    this.setData({
      money: money
    });

  },
  bindcont1(e) {
    let cont = e.detail.value;
    console.log('普通红包祝福内容：==》', cont);
    this.setData({
      cont: cont
    });
  },
  //拼手气红包信息
  bindnum2(e) {
    let num = e.detail.value;
    console.log('拼手气红包祝福内容：==》', num);
    this.setData({
      num: num
    });
  },
  bindmoney2(e) {
    let money = e.detail.value;
    console.log('拼手气红包钱：==》', money);
    this.setData({
      money: money
    });

  },
  bindcont2(e) {
    let cont = e.detail.value;
    console.log('拼手气红包祝福内容：==》', cont);
    this.setData({
      cont: cont
    });
  },
  //口令等额红包信息
  bindnum3(e) {
    let num = e.detail.value;
    console.log('口令等额红包祝福内容：==》', num);
    this.setData({
      num: num
    });
  },
  bindmoney3(e) {
    let money = e.detail.value;
    console.log('口令等额红包钱：==》', money);
    this.setData({
      money: money
    });

  },
  bindpass3(e) {
    let pass = e.detail.value;
    console.log('口令等额红包祝福内容：==》', pass);
    this.setData({
      pass: pass
    });
  },
  //口令随机红包信息
  bindnum4(e) {
    let num = e.detail.value;
    console.log('口令随机红包祝福内容：==》', num);
    this.setData({
      num: num
    });
  },
  bindmoney4(e) {
    let money = e.detail.value;
    console.log('口令随机红包钱：==》', money);
    this.setData({
      money: money
    });

  },
  bindpass4(e) {
    let pass = e.detail.value;
    console.log('口令随机红包祝福内容：==》', pass);
    this.setData({
      pass: pass
    });
  },
  //发红包
  //index.php?act=red_bag&op=send_red_bag
  send_red_bag(type,num,money,pass,cont){
    let that = this;
    let k = wx.getStorageSync('key');
    console.log('key:==>' + k,'type===>'+type, 'num==>' + num, 'money==>' + money, 'pass===>' + pass, 'cont===>' + cont);
    wx.request({
      url: ApiUrl + '/index.php?act=red_bag&op=send_red_bag',
      data: {
        key: k,
        type: type,//红包类型
        num: num,//红包数
        money: money,//钱数
        password: pass,//红包口令
        content: cont//祝福语言
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: 'POST',
      success: function (result) {
        console.log('发红包:==>', result);
        if (result.statusCode == 200) {
          let res = result.data.datas.data;
          if (result.data.code == 200) {
            console.log('发红包:==>', res);
            let resJSON = JSON.stringify(res);
            console.log('发红包:==>', typeof resJSON);
            that.setData({
              send_red_bag_list: resJSON
            });
          } else {
            console.log('发红包:==>', res);

          }
        }
      }
    });
  },
  send_red_bag_btn(){
    let num = this.data.num;
    let money = this.data.money;
    let pass = this.data.pass;
    let cont = this.data.cont;
    let currentTab = this.data.currentTab+1;

    this.send_red_bag(currentTab, num, money, pass, cont);
    this.setData({
      hide_red_bao: true
    });
  },
  hide_red_bao(){
    this.setData({
      hide_red_bao: false
    });
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    this.setData({
      hide_red_bao: false
    });
    let send_data = this.data.send_red_bag_list;
    let currentTab = this.data.currentTab + 1;
    if (send_data!=''){
    if (res.from === 'button') {
      // 来自页面内转发按钮
      if (currentTab == 1) {
        console.log('res.target.id==>', currentTab);
          console.log('======>', send_data, '<========', this.data.send_red_bag_list);
      
        
        return {
          title: '您的好友给您发红包，快来笑纳吧',
          imageUrl: '/image/WechatIMG91.jpeg',//图片地址
          path: '/pages/red_envelopes/Send_red_packets?send_red_bag_datas=' + send_data,// 用户点击首先进入的当前页面
          success: function (res) {
            // 转发成功
            console.log("转发成功:");
          },
          fail: function (res) {
            // 转发失败
            console.log("转发失败:");
          }
        }
      }
      if (currentTab == 2) {
        console.log('res.target.id==>', currentTab);
        let send_red_bag_datas = this.data.send_red_bag_datas;

        return {
          title: '您的好友给您发红包，快来笑纳吧',
          imageUrl: '/image/WechatIMG91.jpeg',//图片地址
          path: '/pages/red_envelopes/Send_red_packets?send_red_bag_datas=' + send_data,// 用户点击首先进入的当前页面
          success: function (res) {
            // 转发成功
            console.log("转发成功:");
          },
          fail: function (res) {
            // 转发失败
            console.log("转发失败:");
          }
        }

      }
      if (currentTab == 3) {
        console.log('res.target.id==>', currentTab);
        let send_red_bag_datas = this.data.send_red_bag_datas;
        return {
          title: '您的好友给您发红包，快来笑纳吧',
          imageUrl: '/image/WechatIMG91.jpeg',//图片地址
          path: '/pages/red_envelopes/Send_red_packets?send_red_bag_datas=' + send_data,// 用户点击首先进入的当前页面
          success: function (res) {
            // 转发成功
            console.log("转发成功:");
          },
          fail: function (res) {
            // 转发失败
            console.log("转发失败:");
          }
        }
      }
      if (currentTab == 4) {
        console.log('res.target.id==>', currentTab);
        let send_red_bag_datas = this.data.send_red_bag_datas;
        return {
          title: '您的好友给您发红包，快来笑纳吧',
          imageUrl: '/image/WechatIMG91.jpeg',//图片地址
          path: '/pages/red_envelopes/Send_red_packets?send_red_bag_datas=' + send_data,// 用户点击首先进入的当前页面
          success: function (res) {
            // 转发成功
            console.log("转发成功:");
          },
          fail: function (res) {
            // 转发失败
            console.log("转发失败:");
          }
        }
      }
    } 

    }

  }
})
